<template>
	<div>
		<Card class="content-card">
			<Tabs :animated="false">
				<ButtonGroup slot="extra">

					<Button type="primary" size="small" icon="md-refresh" @click="refreshData"></Button>
				</ButtonGroup>
				<TabPane label="系统设置--账号管理" name="account">
					<div style="margin-bottom:10px;">
						<Button type="primary" size="small" @click="addUser">添加账号</Button>
					</div>
					<table-view ref="tableView" :tableCol='tableCol' :params="params" :type="modalType" :requestUrl='requestUrl'></table-view>
				</TabPane>
			</Tabs>
		</Card>
		<user-ope ref="userOpe" :type='modalType' @table='operationDone'></user-ope>
	</div>
</template>

<script>
	import tableView from '../../components/table'
	import userOpe from './userOpe'
	import {
		formatDate
	} from '../utils/time.js'
	export default {
		components: {
			tableView,
			userOpe
		},
		data() {
			return {
				requestUrl: '/partslog/list',
				tableCol: [{
						title: '序号',
						type: 'index',
						width: 70
					}, {
						title: '登录帐号',
						key: 'userName',
						minWidth: 180
					}, {
						title: '登录次数',
						key: 'loginNumber',
						minWidth: 180
					}, {
						title: '状态',
						key: 'isOpen',
						minWidth: 150,
						render: (h, params) => {
							return h('div', params.row.isOpen == 0 ? "开启" : "关闭")
						}
					}, {
						title: '操作',
						key: 'action',
						minWidth: 200,
						render: (h, params) => {
							return h('div', [
								h('Button', {
									props: {
										type: 'error',
										size: 'small'
									},
									on: {
										click: () => {
											this.$Modal.confirm({
												title: '删除？',
												content: '确定要删除吗？删除不可恢复',
												onOk: () => {
													this.$http.post('/partslog/delete', {
														id: params.row.partsId
													}).then(res => {
														if (res.status == 200) {
															this.$refs['tableView'].getData()
															this.$Notice.warning({
																title: '删除成功'

															});
														}
													})
												}
											})
										}
									}
								}, '删除'),
								h('Button', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										marginLeft: '10px'
									},
									on: {
										click: () => {
											this.$Modal.confirm({
												title: '重置密码',
												content: '确定要重置密码吗',
												onOk: () => {
													this.$http.post('/partslog/reset/pwd', {
														hostsId: params.row.hostsId
													}).then(res => {
														if (res.status == 200) {
															this.$refs['tableView'].getData()
															this.$Notice.warning({
																title: '重置成功'
											
															});
														}
													})
												}
											})
								
										}
									}
								}, '重置密码'),
								h('Button', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										marginLeft: '10px'
									},
									on: {
										click: () => {
											this.modalType = 'edit'
											this.$refs['userOpe'].show(params)

										}
									}
								}, '编辑')
							])
						}
					}

				],
				params: {
					pageNo: 1,
					pageSize: 10,
					factoryId: sessionStorage.getItem("factoryId")
				},
				modalType: ''
			}
		},
		mounted() {

		},
		methods: {
			addUser() {
				this.modalType = 'add'
				this.$refs['userOpe'].show()
			},
			refreshData() {
				this.$refs['tableView'].getData()
			},
			operationDone() {
				this.$refs['tableView'].getData()
			}
		}
	}
</script>
<style scoped>

</style>
